#ifndef LEVELEDITOR_H
#define LEVELEDITOR_H

#include <QtGui>
#include "commons.h"

class LevelEditor : public QObject, QGraphicsItem
{
    Q_OBJECT
    Q_INTERFACES(QGraphicsItem)
public:
    explicit LevelEditor(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QRectF boundingRect() const;
    void setEditingLevel(Level *level);
    Level *getEditingLevel() {return currentLevel;}
//    const QLinkedList<Point*>& getPointsList();
//    const QLinkedList<Line*>& getLinesList();

signals:
    void returnClicked();
    void lineClicked();
    void pointClicked();
    void saveClicked(const QString &name);
    void loadClicked();

    void pointHoverEnter();
    void pointHoverLeave();
    void lineHoverEnter();
    void lineHoverLeave();
    void linerHoverEnter();
    void linerHoverLeave();
    void canvasHoverEnter(CanvasState state);
    void canvasHoverLeave();
    void pointDragStart();
    void pointDragStop();
    void lineDragStart();
    void lineDragStop();
    void lineringStop();

public slots:
    void clicked(ButtonItem *who);
    void dialogClosed();
    void doSaveClicked(const QString &name);

    void pointHoverEntered();
    void pointHoverLeft();
    void lineHoverEntered();
    void lineHoverLeft();
    void linerHoverEntered();
    void linerHoverLeft();
    void canvasHoverEntered(CanvasState state);
    void canvasHoverLeft();
    void pointDragStarted();
    void pointDragStoped();
    void lineDragStarted();
    void lineDragStoped();
    void lineringStoped();

private:
    ImageItem *background;
    SaveLevelDialog *saveDialog;
    ButtonItem *pointBg;
    ButtonItem *lineBg;
    ButtonItem *loadBg;
    ButtonItem *saveBg;
    ButtonItem *returnBg;
    Canvas *canvas;

    Level *currentLevel;

    void initScene();
    void initEventSystem();
    void enableButtons(bool enabled);
    void setDisplayName(const QString &name);
    void saveToCurrentLevel(const QString &name);

};

#endif // LEVELEDITOR_H
